package zozopo.user;

import java.sql.Connection;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;

import zozopo.database.BusiDatabaseManager;
import zozopo.operations.comm.DictionaryOS;
import zozopo.operations.comm.DictionaryTB;
import zozopo.user.operations.UserOS;
import zozopo.user.operations.UserTB;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class InfoAction extends ActionSupport implements Action,SessionAware,ServletRequestAware,ServletResponseAware{
	HttpServletRequest request;
	HttpServletResponse response;
	private Map<Object, Object> session;
	
	//转入参数
	private int id;
	private String usermail;
	
	
	//QQ参数
	private String access_token ="";
	private String expires_in = "";
	
	//输出
	private UserTB user;
	
	private  Map<String,DictionaryTB> limitMap;
	



	public Map<String, DictionaryTB> getLimitMap() {
		return limitMap;
	}


	public void setLimitMap(Map<String, DictionaryTB> limitMap) {
		this.limitMap = limitMap;
	}


	public UserTB getUser() {
		return user;
	}


	public void setUser(UserTB user) {
		this.user = user;
	}


	public String getUsermail() {
		return usermail;
	}


	public void setUsermail(String usermail) {
		this.usermail = usermail;
	}


	public String execute(){
		BusiDatabaseManager databaseConnection = new BusiDatabaseManager();
		Connection conn = databaseConnection.getConnection();
		
		//UserTB user = (UserTB) session.get("userInfo");
		
		UserOS userOS = new UserOS(conn);
		if(usermail != null){
			user = userOS.getUserInfo(id);
		}else{
			user = (UserTB) session.get("userInfo");
		}
		
		
		DictionaryOS dictionaryOS = new DictionaryOS(conn);
		limitMap = dictionaryOS.getDictionaryLimitMap();
		
		databaseConnection.releaseConnection(conn);
		if(user == null)
		{
			return ERROR;
		}
		
		
		return SUCCESS;
	}
	
	



	public void setServletRequest(HttpServletRequest arg0) {
		// TODO Auto-generated method stub
		request = arg0;
	}

	public void setSession(Map arg0) {
		// TODO Auto-generated method stub
		session = arg0;
	}

	public void setServletResponse(HttpServletResponse arg0) {
		// TODO Auto-generated method stub
		response = arg0;
		response.setCharacterEncoding("GB2312");
		response.setContentType("text/xml; charset=gb2312");
	}


	public int getId() {
		return id;
	}


	public void setId(int id) {
		this.id = id;
	}


	public String getAccess_token() {
		return access_token;
	}


	public void setAccess_token(String access_token) {
		this.access_token = access_token;
	}


	public String getExpires_in() {
		return expires_in;
	}


	public void setExpires_in(String expires_in) {
		this.expires_in = expires_in;
	}
}
